class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        int sum = 0;
        for(int e : nums){
            sum += e;
        }
        int lS = 0;
        int rS = 0;
        for(int i = 0;i < nums.size();i++){
            lS += nums[i];
            rS = sum - lS + nums[i];
            if(lS == rS){
                return i;
            }
        }
        return -1;
    }
};
